package studay.observe;

import java.util.Vector;

/**
 * @program: 设计模式
 * @description:
 * @author: Tom
 * @create: 2022-01-07 23:17
 **/
public class Subject {
    private Vector<Observer> observersVector = new Vector<>();

    /**
     * 新增观察者
     * @param observer
     */
    public void addObserver(Observer observer){
        this.observersVector.add(observer);
    }

    /**
     * 删除观察者
     * @param observer
     */
    public void deleteObserver(Observer observer){
        this.observersVector.remove(observer);
    }

    public void notifyAllObserver(){
        for (Observer observer:this.observersVector){
             observer.update();
        }
    }
}
